<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="../include/laypublic.jsp"%>
<!DOCTYPE html>
<html>
<head>
</head>
<title>合作单位信息</title>
<style type="text/css">
	.layui-form-select dl {
		max-height: 150px;
	}
	.fieldset{
		margin-top: 5px;
		margin-bottom: 0px
	}
	.layui-legend{
		background-color:#5fb878;
		font-size:15px !important;
		width:130px;
	}
	.layui-form-item {
	    margin-bottom: 5px;
	    clear: both;
	    *zoom: 1;
	}
	.layui-form-label{width: 159px;}
	.right{
		float:right;
	}
	.width106{
		width:106px;
	}
	.width98{
		width:98px;
	}
	.width60{
		width:60px;
	}
	.width30{
		width:30px;
	}
</style>
</head>
<body>
	<div class="layui-fluid">
		<div class="layui-card">
			<!-- 查询区域  -->
			<div id="query-form"
				class="layui-form layui-card-header layuiadmin-card-header-auto">
				<div class="layui-form-item">
					<div class="layui-inline">
						<label class="layui-form-label" style="width:130px;">单位名称</label>
						<div class="layui-input-inline">
							<input type="text" name="coopName" placeholder="请输入单位名称"
								autocomplete="off" class="layui-input">
						</div>
					</div>
					<div class="layui-inline">
						<label class="layui-form-label" style="width:130px;">所在城市</label>
						<div class="layui-input-inline">
							<input type="text" name="cityName" placeholder="请输入所在城市"
								autocomplete="off" class="layui-input">
						</div>
					</div>
					<div class="layui-inline">
						<label class="layui-form-label" style="width:130px;">单位类别</label>
						<div class="layui-input-inline">
							<infopub:select entireName="-单位类别" id="query-form-companyType"
								name="types" type="dic" groupNo="A00010059">
							</infopub:select>
						</div>
					</div>
					<shiro:hasPermission name="LIST_COOPINFO">
						<div class="layui-inline">
							<button class="layui-btn layuiadmin-btn-admin" lay-submit
								lay-filter="LAY-coopinfo-search">
								<i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>查询
							</button>
							<button class="layui-btn layuiadmin-btn-admin" lay-submit lay-filter="LAY-user-back-reset">
	              				<i class="layui-icon layui-icon-fonts-clear  layuiadmin-button-btn"></i>重置
	            			</button>
						</div>
					</shiro:hasPermission>
				</div>
			</div>
	<!-- 按钮区域  -->
    <div class="layui-card-body">
        <div style="padding-bottom: 10px;">
				<shiro:hasPermission name="SAVE_COOPINFO">
					<button class="layui-btn layuiadmin-btn-admin " data-type="add">
						<i class="layui-icon layui-icon-add-1 layuiadmin-button-btn"></i>新增
					</button>
				</shiro:hasPermission>
				<shiro:hasPermission name="EXPORT_COOPINFO">
	          		<button class="layui-btn layuiadmin-btn-admin " data-type="export" onclick="exportList();">
	          	 		<i class="layui-icon layui-icon-export layuiadmin-button-btn"></i>导出
	          		</button>
          		</shiro:hasPermission>
		</div>
			<!-- 数据表单 -->
			<table id="LAY-coopinfo-manage" lay-filter="LAY-coopinfo-manage"></table>
			<!-- 新建合作单位窗口 -->
			<div class="layui-form" lay-filter="add_form" id="add_form"
				style="padding: 20px 30px 0 0; display: none">
				<fieldset class="layui-elem-field layui-field-title fieldset"  id="baseInfo">
				  <legend class="layui-btn layui-legend" style="text-align:left;cursor:default;">基础信息></legend>
				<div class="layui-form-item" style="height:10px;"></div>
				<div class="layui-form-item">
					<div class="layui-inline">
						<label class="layui-form-label">单位全称</label>
						<div class="layui-input-inline">
							<input type="text" name="coopName" maxlength="50" style="width:300px;"
								lay-verify="required|COC"
								placeholder="请输入合作单位名称" autocomplete="off" class="layui-input">
						</div>
					</div>
				</div>
				<div class="layui-form-item">
					<div class="layui-inline">
						<label class="layui-form-label">所在城市</label>
						<div class="layui-input-inline">
							<select name="provinceCode" id="query-select-provinceCode"
								lay-filter="query-select-provinceCode" lay-verify="required"
								lay-search>
								<option value="">请选择</option>
								<c:if test="${not empty provinces }">
									<c:forEach items="${provinces}" var="pvn">
										<option value="${pvn.id }">${pvn.sname }</option>
									</c:forEach>
								</c:if>
							</select>
						</div>
						<div class="layui-input-inline">
							<select name="cityCode" id="query-select-cityCode"
								lay-filter="query-select-cityCode" lay-verify="required"
								lay-search>
							</select>
						</div>
						<div class="layui-input-inline">
							<select name="areaCode" id="query-select-areaCode"
								lay-search>
							</select>
						</div>
					</div>
				</div>
				<div class="layui-form-item">
					<div class="layui-inline">
						<label class="layui-form-label">单位类别</label>
						<div class="layui-input-inline">
							<infopub:select entireName="-单位类别" id="query-form-coopType"
								name="types" type="dic" groupNo="A00010059">
							</infopub:select>
						</div>
					</div>
					<div class="layui-inline">
						<label class="layui-form-label">成立年份</label>
						<div class="layui-input-inline">
							<input type="text" name="upYear" maxlength="50"
								lay-verify="required|yearNumber"
								placeholder="请输入成立年份"
								autocomplete="off" class="layui-input">
						</div>
					</div>
				</div>
				<div class="layui-form-item">
					<div class="layui-inline">
						<label class="layui-form-label">注册资金（万元）</label>
						<div class="layui-input-inline">
							<input type="text" name="regCapital" maxlength="50"
								lay-verify="required|doubleNumber"
								placeholder="请输入注册资金" onblur="isNumberAndFloat1(this);arabiaToCN(this,2);"
								autocomplete="off" class="layui-input">
						</div>
					</div>
					<div class="layui-inline">
						<label class="layui-form-label">法人</label>
						<div class="layui-input-inline">
							<input type="text" name="legalPerson" maxlength="50"
								lay-verify="required|CHS"
								placeholder="请输入法人姓名" autocomplete="off" class="layui-input">
						</div>
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">经营范围</label>
					<div class="layui-input-block">
						<textarea name="bizScope" class="layui-textarea" maxlength="1000"
							lay-verify="required" style="width: 595px; height: 90px;"></textarea>
					</div>
				</div>
				</fieldset>
				<fieldset class="layui-elem-field layui-field-title fieldset"  id="baseInfo">
				  <legend class="layui-btn layui-legend" style="text-align:left;cursor:default;">详细信息></legend>
				<div class="layui-form-item" style="height:10px;"></div>
				<div class="layui-form-item">
					<label class="layui-form-label">代表工程（选填）</label>
					<div class="layui-input-block">
						<textarea name="representWorks" class="layui-textarea"
							maxlength="100" style="width: 595px; height: 90px;"></textarea>
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">简介及评价（选填）</label>
					<div class="layui-input-block">
						<textarea name="synopsis" class="layui-textarea" maxlength="100"
							style="width: 595px; height: 90px;"></textarea>
					</div>
				</div>
				</fieldset>
				<fieldset class="layui-elem-field layui-field-title fieldset"  id="baseInfo">
				  <legend class="layui-btn layui-legend" style="text-align:left;cursor:default;">联系人信息></legend>
				<div class="layui-form-item" style="height:10px;"></div>
				<div class="layui-form-item">
					<div class="layui-inline">
						<label class="layui-form-label">联系人</label>
						<div class="layui-input-inline">
							<input type="text" name="linkMan" maxlength="50"
								placeholder="请输入联系人名"
								autocomplete="off" lay-verify="required|CHS" class="layui-input">
						</div>
					</div>
					<div class="layui-inline">
						<label class="layui-form-label">联系人电话</label>
						<div class="layui-input-inline">
							<input type="text" name="linkPhone" maxlength="50"
								lay-verify="required|telNumber"
								placeholder="请输入联系人电话"
								autocomplete="off" class="layui-input">
						</div>
					</div>
				</div>
				</fieldset>
				<div class="layui-form-item layui-hide">
					<input type="button" lay-submit lay-filter="add_form_submit"
						id="add_form_submit" value="确认保存">
				</div>
			</div>
			<!-- 合作单位详情窗口 -->
			<div class="layui-form" lay-filter="detail_form" id="detail_form"
				style="padding: 20px 30px 0 0; display: none">
				<fieldset class="layui-elem-field layui-field-title fieldset"  id="baseInfo">
				  <legend class="layui-btn layui-legend" style="text-align:left;cursor:default;">基础信息></legend>
				<div class="layui-form-item" style="height:10px;"></div>
				<div class="layui-form-item">
					<div class="layui-inline">
						<label class="layui-form-label">单位ID</label>
						<div class="layui-input-inline">
							<input type="text" name="coopCode" style="border: 0px;"
								readonly="readonly" class="layui-input">
						</div>
					</div>
					<div class="layui-inline">
						<label class="layui-form-label">单位全称</label>
						<div class="layui-input-inline">
							<input type="text" name="coopName"
								style="border: 0px; " readonly="readonly"
								class="layui-input">
						</div>
					</div>
				</div>
				<div class="layui-form-item">
					<div class="layui-inline">
						<label class="layui-form-label">所在城市</label>
						<div class="layui-input-inline">
							<input type="text" name="cityName" style="border: 0px;"
								readonly="readonly" class="layui-input">
						</div>
					</div>
					<div class="layui-inline">
						<label class="layui-form-label">单位类别</label>
						<div class="layui-input-inline">
							<infopub:select entireName="-单位类别" id="query-form-coopType"
								name="types" type="dic" groupNo="A00010059" disabled="disabled">
							</infopub:select>
						</div>
					</div>
					<div class="layui-inline">
						<label class="layui-form-label">成立年份</label>
						<div class="layui-input-inline">
							<input type="text" name="upYear" style="border: 0px;"
								readonly="readonly" class="layui-input">
						</div>
					</div>
				</div>
				<div class="layui-form-item">
					<div class="layui-inline">
						<label class="layui-form-label">注册资金（万元）</label>
						<div class="layui-input-inline">
							<input type="text" name="regCapital" style="border: 0px;"
								readonly="readonly" onload="thousandSplit(this)"
								class="layui-input">
						</div>
					</div>
					<div class="layui-inline">
						<label class="layui-form-label">法人</label>
						<div class="layui-input-inline">
							<input type="text" name="legalPerson" style="border: 0px;"
								readonly="readonly" class="layui-input">
						</div>
					</div>
				</div>
				<div class="layui-form-item">
					<div class="layui-inline">
						<label class="layui-form-label">经营范围</label>
						<div class="layui-input-inline">
							<textarea name="bizScope" class="layui-textarea"
								readonly="readonly"
								style="width: 520px; height: 90px;"></textarea>
						</div>
					</div>
				</div>
			</fieldset>
			<fieldset class="layui-elem-field layui-field-title fieldset"  id="baseInfo">
				  <legend class="layui-btn layui-legend" style="text-align:left;cursor:default;">详细信息></legend>
				<div class="layui-form-item" style="height:10px;"></div>
				<div class="layui-form-item">
					<div class="layui-inline">
						<label class="layui-form-label">代表工程</label>
						<div class="layui-input-inline">
							<textarea name="representWorks" class="layui-textarea"
								readonly="readonly"
								style="width: 520px; height: 90px;"></textarea>
						</div>
					</div>
				</div>
				<div class="layui-form-item">
					<div class="layui-inline">
						<label class="layui-form-label">简介及评价</label>
						<div class="layui-input-inline">
							<textarea name="synopsis" class="layui-textarea"
								readonly="readonly"
								style="width: 520px; height: 90px;"></textarea>
						</div>
					</div>
				</div>
			</fieldset>
			<fieldset class="layui-elem-field layui-field-title fieldset"  id="baseInfo">
				  <legend class="layui-btn layui-legend" style="text-align:left;cursor:default;">联系人信息></legend>
				<div class="layui-form-item" style="height:10px;"></div>
				<div class="layui-form-item">
					<div class="layui-inline">
						<label class="layui-form-label">联系人</label>
						<div class="layui-input-inline">
							<input type="text" name="linkMan" style="border: 0px;"
								readonly="readonly" class="layui-input">
						</div>
					</div>
					<div class="layui-inline">
						<label class="layui-form-label">联系人电话</label>
						<div class="layui-input-inline">
							<input type="text" name="linkPhone" style="border: 0px;"
								readonly="readonly" class="layui-input">
						</div>
					</div>
				</div>
			</fieldset>
			<fieldset class="layui-elem-field layui-field-title fieldset"  id="baseInfo">
				  <legend class="layui-btn layui-legend" style="text-align:left;cursor:default;">保存记录></legend>
				<div class="layui-form-item" style="height:10px;"></div>
				<div class="layui-form-item">
					<div class="layui-inline" style="padding-left: 185px;">
						<table id="coopInfoLog" class="lay-table">
						</table>
					</div>
				</div>
			</fieldset>
				<div class="layui-form-item layui-hide">
					<input type="button" lay-filter="detail_form_submit"
						id="detail_form_submit" value="确认保存">
				</div>
			</div>

			<!-- 编辑合作单位窗口 -->
			<div class="layui-form" lay-filter="edit_form" id="edit_form"
				style="padding: 20px 30px 0 0; display: none">
				<fieldset class="layui-elem-field layui-field-title fieldset"  id="baseInfo">
				  <legend class="layui-btn layui-legend" style="text-align:left;cursor:default;">基础信息></legend>
				<div class="layui-form-item" style="height:10px;"></div>
				<div class="layui-form-item">
					<div class="layui-inline">
						<label class="layui-form-label">单位全称</label>
						<div class="layui-input-inline">
							<input type="text" name="coopName" maxlength="50" style="width:300px;"
								lay-verify="required|COC"
								placeholder="请输入合作单位名称" autocomplete="off" class="layui-input">
						</div>
					</div>
				</div>
				<div class="layui-form-item">
					<div class="layui-inline">
						<label class="layui-form-label">所在城市</label>
						<div class="layui-input-inline">
							<select name="refProvinceId" id="query-select-refProvinceId"
								lay-filter="query-select-refProvinceId" lay-verify="required"
								lay-search>
								<option value="">请选择</option>
								<c:if test="${not empty provinces }">
									<c:forEach items="${provinces}" var="pvn">
										<option value="${pvn.id }">${pvn.sname }</option>
									</c:forEach>
								</c:if>
							</select>
						</div>
						<div class="layui-input-inline">
							<select name="refCityId" id="query-select-refCityId"
								lay-filter="query-select-refCityId" lay-verify="required"
								lay-search>
							</select>
						</div>
						<div class="layui-input-inline">
							 <select name="refAreaId" id="query-select-refAreaId"
								lay-search>
							</select>
						</div>
					</div>
				</div>
				<div class="layui-form-item">
					<div class="layui-inline">
						<label class="layui-form-label">单位类别</label>
						<div class="layui-input-inline">
							<infopub:select entireName="-单位类别" id="query-form-coopType"
								name="types" type="dic" groupNo="A00010059">
							</infopub:select>
						</div>
					</div>
					<div class="layui-inline">
						<label class="layui-form-label">成立年份</label>
						<div class="layui-input-inline">
							<input type="text" name="upYear" maxlength="50"
								lay-verify="required|yearNumber"
								placeholder="请输入成立年份"
								autocomplete="off" class="layui-input">
						</div>
					</div>
				</div>
				<div class="layui-form-item">
					<div class="layui-inline">
						<label class="layui-form-label">注册资金（万元）</label>
						<div class="layui-input-inline">
							<input type="text" name="regCapital" maxlength="50"
								lay-verify="required|doubleNumber"
								placeholder="请输入注册资金" onblur="isNumberAndFloat1(this);arabiaToCN(this,2);"
								autocomplete="off" class="layui-input">
						</div>
					</div>
					<div class="layui-inline">
						<label class="layui-form-label">法人</label>
						<div class="layui-input-inline">
							<input type="text" name="legalPerson" maxlength="50"
								lay-verify="required|CHS"
								placeholder="请输入法人姓名" autocomplete="off" class="layui-input">
						</div>
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">经营范围</label>
					<div class="layui-input-block">
						<textarea name="bizScope" class="layui-textarea" maxlength="1000"
							lay-verify="required" style="width: 595px; height: 90px;"></textarea>
					</div>
				</div>
			</fieldset>
			<fieldset class="layui-elem-field layui-field-title fieldset"  id="baseInfo">
				  <legend class="layui-btn layui-legend" style="text-align:left;cursor:default;">详细信息></legend>
				<div class="layui-form-item" style="height:10px;"></div>
				<div class="layui-form-item">
					<label class="layui-form-label">代表工程（选填）</label>
					<div class="layui-input-block">
						<textarea name="representWorks" class="layui-textarea"
							maxlength="100" style="width: 595px; height: 90px;"></textarea>
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">简介及评价（选填）</label>
					<div class="layui-input-block">
						<textarea name="synopsis" class="layui-textarea" maxlength="100"
							style="width: 595px; height: 90px;"></textarea>
					</div>
				</div>
			</fieldset>
			<fieldset class="layui-elem-field layui-field-title fieldset"  id="baseInfo">
				  <legend class="layui-btn layui-legend" style="text-align:left;cursor:default;">联系人信息></legend>
				<div class="layui-form-item" style="height:10px;"></div>
				<div class="layui-form-item">
					<div class="layui-inline">
						<label class="layui-form-label">联系人</label>
						<div class="layui-input-inline">
							<input type="text" name="linkMan" maxlength="50"
								placeholder="请输入联系人名"
								autocomplete="off" lay-verify="required|CHS" class="layui-input">
						</div>
					</div>
					<div class="layui-inline">
						<label class="layui-form-label">联系人电话</label>
						<div class="layui-input-inline">
							<input type="text" name="linkPhone" maxlength="50"
								lay-verify="required|telNumber"
								placeholder="请输入联系人电话"
								autocomplete="off" class="layui-input">
						</div>
					</div>
				</div>
			</fieldset>
				<div class="layui-form-item layui-hide">
					<input type="button" lay-submit lay-filter="edit_form_submit"
						id="edit_form_submit" value="确认保存">
				</div>
			</div>
		</div>
	</div>
</div>
	<script>
  	layui.config({
    	base: '${ctx}/resources/layuiadmin/' //静态资源所在路径
  	}).extend({
    	index: 'lib/index' //主入口模块
  	}).use(['index', 'table', 'set', 'layedit'], function(){
    	var $ = layui.$
    	,form = layui.form
    	,table = layui.table
    	,layedit = layui.layedit

    	// 正则校验
    	form.verify({
    		//验证汉字
    	    CHS: [
    	    	/^[\u0391-\uFFE5]+$/
    	    	,'只能输入汉字'
    	  	],
    	  	//公司名字校验
    	  	COC: [
				/^[\u4e00-\u9fa5_a-zA-Z0-9 （）()]+$/
				,'请输入正确的名称'
    	  	],
	    	//大于0的正整数
		  	intNumber:[
				/^[1-9]\d*$/
				,'请输入正确的数字'
		  	],
		  	yearNumber:[
				/[0-9]{3}[1-9]|[0-9]{2}[1-9][0-9]{1}|[0-9]{1}[1-9][0-9]{2}|[1-9][0-9]{3}/
				,'请输入正确的年份'
		  	],
		  	telNumber:[
		  	    /^((0\d{2,3}-\d{7,8})|([1][3,4,5,7,8,9][0-9]{9}))$/
		  	    ,'请输入正确的号码'
		  	],
		  	//大于0的对多保留2位小数正数
		  	doubleNumber:[
				/^\d+(\.\d{0,2})?$/
				,'请输入正确的数字'
		  	]
		});

    	// 表单
    	table.render({
      		elem: '#LAY-coopinfo-manage'
      		,url: basePath + '/coopinfo/queryCoopInfo' //请求数据接口
      		,cols: [[
        		{type: 'checkbox', fixed: 'left'}
        		,{field: 'coopCode', title: '单位ID'}
        		,{field: 'coopName', title: '单位名称'}
        		,{field: 'addTime', title: '创建时间', templet: function(d){
            		  	return layui.util.toDateString(d.addTime,"yyyy-MM-dd HH:mm:ss");
	              	}
	             }
        		,{field: 'cityName', title: '所在城市'}
        		,{field: 'types', title: '单位类别',
        			templet: function(d){
            		  	if(d.types=='1'){
            		  		return d.types='联合体单位'
            		  	}else if(d.types=="2"){
            		  		return d.types='承贷企业'
        	            }else if(d.types=="3"){
        	            	return d.types='总包单位'
        	            }else if(d.types=="4"){
        	            	return d.types='分包单位'
        	            }else if(d.types=="5"){
        	            	return d.types='设备单位'
        	            }else if(d.types=="9"){
        	            	return d.types='其他单位'
        	            }
	              	}
        		 }
        		,{field: 'uptTime', title: '最后修改时间' ,templet: function(d){
        		  	return layui.util.toDateString(d.uptTime,"yyyy-MM-dd HH:mm:ss");
              		}
        		}
        		,{field: 'srealName', title: '最后修改人',templet:function (d) {
						if (d.operator && d.operator.srealName){
							return d.operator.srealName;
						}else{
							return '';
						}
					}
                }
        		,{title: '操作', width: 220, align:'center', fixed: 'right', templet: function(d){
      	  				var optStr ="";
      	  				<shiro:hasPermission name="VIEW_COOPINFO">
      	  				optStr += '<a class="layui-btn layui-btn-xs" lay-event="view"><i class="layui-icon layui-icon-form"></i>详情</a>';
      	  				</shiro:hasPermission>
      	  				<shiro:hasPermission name="UPDATE_COOPINFO">
      	 					optStr += '<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>修改</a>';
  	  	  				</shiro:hasPermission>
			  		  	return optStr;
        			}
        		}
      			]]
      		,page: true
      		,limit: 10
    	});

    	<shiro:hasPermission name="LIST_COOPINFO">
	    	//监听搜索
	    	form.on('submit(LAY-coopinfo-search)', function(data){
		      	//执行重载
		      	table.reload('LAY-coopinfo-manage', {page: {curr: 1},
		        	where: trimData(data)
		      	});
	    	});
	    	//重置清空
		    form.on('submit(LAY-user-back-reset)', function(data){
		    	reset_form('query-form');
		    	//额外处理select
				$("#query-form-state").val('');
				form.render();
		    });
    	</shiro:hasPermission>

    	// 监听操作列
    	table.on('tool(LAY-coopinfo-manage)', function(obj){
      		var data = obj.data;
      		if(obj.event === 'edit'){
      			form.val('edit_form',data); // 填充原值
      			$('#query-select-refCityId').html('');
      	        $('#query-select-refAreaId').html('');
	      		getCityByProvinceId($('#query-select-refCityId'),data.refProvinceId,data.refCityId);
	        	getAreaByCityId($('#query-select-refAreaId'),data.refCityId,data.refAreaId);
      			layer.open({
            		type: 1
            		,title: '修改合作单位信息'
            		,content: $('#edit_form')
            		,area: layui.admin.screen() < 2 ? ['80%', '550px'] : ['850px','550px']
            		,btn: ['确定', '取消']
            		,btnAlign: 'c'
            		,yes: function(index, layero){
          	  			var submitID = 'edit_form_submit'
          		  		,submit = layero.contents().find('#'+ submitID);
          	  			//监听提交
          	  			form.on('submit('+ submitID +')', function(datas){
	                      	var field = datas.field; //获取提交的字段
                			//提交 Ajax 成功后，静态更新表格中的数据
                			$.ajax({
                    			type : 'post',
  								url : basePath + '/coopinfo/editCoop?id='+data.id,
                    			data: field,
  								success:function(result){
  									if(result.success){
                						table.reload('LAY-coopinfo-manage'); //数据刷新
                						layer.close(index); //关闭弹层
  									}else{
  										layer.msg(result.msg,{icon: 7});
  					  				}
  								}
                			});
              			});
              		submit.trigger('click');
           		}
          	});
       	} else if(obj.event === 'view'){
            //获取详情页面的保存记录
            //保存记录表单
	         table.render({
	            elem: '#coopInfoLog'
	            ,url: basePath + '/coopinfo/selectById?coopInfoId='+data.id //请求数据接口
	            ,cols: [[
	              {field: 'saveTime', title: '保存时间',align:'center',width:220,
	                templet:function(d){
	                 return layui.util.toDateString(d.saveTime,"yyyy-MM-dd HH:mm:ss")
                }}
               	  ,{field: 'saveName', title: '保存人',align:'center',width:220}
	             ]]
	            ,page: false
	            ,limit: 10
	         });
	           form.val('detail_form',data); // 填充原值
	             layer.open({
	                  type: 1
	                  ,title: '合作单位详情'
	                  ,content: $('#detail_form')
	                  ,area: layui.admin.screen() < 2 ? ['80%', '550px'] : ['850px','550px']
	                });
	          }else{
	           layer.msg('数据通信异常~',{icon: 0});
	          }
      });

    // 按钮事件
    var active = {
      add: function(){
    	clean_form("add_form");//清空表单
        layer.open({
          type: 1
          ,title: '合作单位信息'
          ,content: $('#add_form')
          ,area: layui.admin.screen() < 2 ? ['80%', '550px'] : ['850px','550px']
          ,btn: ['确定', '取消']
          ,btnAlign: 'c'
          ,yes: function(index, layero){
        	  var submitID = 'add_form_submit'
            	,submit = layero.contents().find('#'+ submitID);

              //监听提交
           	  form.on('submit('+ submitID +')', function(data){
              	var field = data.field; //获取提交的字段
              	//提交 Ajax 成功后，静态更新表格中的数据
              	$.ajax({
                  	type : 'post',
					url : basePath + '/coopinfo/addCoop',
                  	data: field,
					success:function(result){
						if(result.success){
              				table.reload('LAY-coopinfo-manage'); //数据刷新
              				clean_form("add_form");//清空表单
              				layer.close(index); //关闭弹层
              				/* //额外处理select
  						    $("#add_from-compId").val('');
  						    form.render("select"); */
						}else{
							layer.msg(result.msg,{icon: 7});
					  	}
					}
              	});
            });
            submit.trigger('click');
          }
        });
      }
    }
    // data-type事件
    $('.layui-btn.layuiadmin-btn-admin').on('click', function(){
      var type = $(this).data('type');
      active[type] ? active[type].call(this) : '';
    });
	 // 新增-合作单位省份select监听
    form.on('select(query-select-provinceCode)', function(data){
    	var provinceCode = data.value;
    	$('#query-select-cityCode').html('');
    	$('#query-select-areaCode').html('');
    	getCityByProvinceId($('#query-select-cityCode'),provinceCode);
	});

  	//新增-合作单位城市select监听
    form.on('select(query-select-cityCode)', function(data){
    	var cityCode = data.value;
    	$('#query-select-areaCode').html('');
    	getAreaByCityId($('#query-select-areaCode'),cityCode)
	});

	 // 修改-合作单位省份select监听
    form.on('select(query-select-refProvinceId)', function(data){
   		var provinceCode = data.value;
   		$('#query-select-refCityId').html('');
   		$('#query-select-refAreaId').html('');
		getCityByProvinceId($('#query-select-refCityId'),provinceCode);
	});
 	//修改-合作单位城市select监听
    form.on('select(query-select-refCityId)', function(data){
   		var cityCode = data.value;
   		$('#query-select-refAreaId').html('');
		getAreaByCityId($('#query-select-refAreaId'),cityCode)
	});

  });
  	var $ = layui.$;
  	var layer = layui.layer;

  	/**校验合作单位名是否存在（新增时使用）*/
	function checkCoopName(obj){
		var flag = true;
		$.post(
				"${ctx}/coopinfo/checkCoopNameIsExist",
				{
					"coopName":obj.value
				},
				function(data){//data: true 公司名已存在, false 公司名不存在
					if(data){//符合格式,到后台校验 输入的公司名,是否存在
						layui.layer.alert('该合作单位已存在',{icon: 0});
						flag = false;
					}
				});
		return flag;
	}
	/**校验合作单位名是否存在（编辑时使用）*/
	function checkNewCoopName(obj){
		var $ = layui.$;
		var flag = true;
		$.post(
				"${ctx}/org/checkNewCoopNameIsExist",
				{
					"coopName":obj.value,
					"id":$("#editCoopCode").val()
				},
				function(data){//data: true 手机号被占用, false 手机号未被占用
					if(data){//符合格式,到后台校验 输入的新手机号,是否被占用
						layui.layer.alert('该合作单位已存在',{icon: 0});
						flag = false;
					}

				});
		return flag;
	}

	//添加验证
  	function verify(obj,verType){
		var $ = layui.$;
		if(obj.value != null && obj.value != ''){
			$(obj).attr("lay-verify",verType);
		}else{
			$(obj).removeAttr("lay-verify");
		}
	}
	//千位分隔符
  	function thousandSplit(str){
  	  var iNum = str.length % 3;
  	  var prev = '';
  	  var iNow = 0;
  	  var temp = '';
  	  var arr = [];
  	  if (iNum != 0){
  	    prev = str.substring(0, iNum);
  	    arr.push(prev);
  	  }
  	  str = str.substring(iNum);
  	  for (var i = 0; i < str.length; i++){
  	    iNow++;
  	    temp += str[i];
  	    if (iNow == 3 && temp){
  	      arr.push(temp);
  	      temp = '';
  	      iNow = 0;
  	    }
  	  }
  	  return arr.join(',');
  	}

	function getCityByProvinceId(obj,provinceCode,cityId){
		var $ = layui.$
    	,form = layui.form
		//获取省份下的所有城市
		$.ajax({
			type : "POST", //提交方式
			url : "${ctx}/coopinfo/getCityByPro",//路径
			data : {
				"provinceCode" :provinceCode
			},//数据，这里使用的是Json格式进行传输
			success : function(result) {//返回数据根据结果进行相应的处理
				if(result.flag==true){
					var strBuffer = "";
					strBuffer+= '<option value="">请选择</option>';
					layui.$.each(result.citys, function(i,item){
						if(item.id != null && item.sname != null){
							strBuffer+= '<option value='+item.id;
							if(cityId!=undefined&&cityId==item.id){
								strBuffer+= ' selected';
							}
							strBuffer+= '>'+item.sname+'</option>';
						}
			        });
					obj.append(strBuffer);
					form.render();
				}else{
					layer.msg('数据通信异常~',{icon: 0});
				}
			}
		});
	}
	function getAreaByCityId(obj,cityCode,areaId){
		var $ = layui.$
    	,form = layui.form
		//获取城市下的区县
    	$.ajax({
			type : "POST", //提交方式
			url : "${ctx}/coopinfo/getAreaByCity",//路径
			data : {
				"cityCode" :cityCode
			},//数据，这里使用的是Json格式进行传输
			success : function(result) {//返回数据根据结果进行相应的处理
				if(result.flag == true){
					var strBuffer = "";
					strBuffer+= '<option value="">请选择</option>';
					layui.$.each(result.areas, function(i,item){
						strBuffer+= '<option value='+item.id;
						if(areaId!=undefined&&areaId==item.id){
							strBuffer+= ' selected';
						}
						strBuffer+= '>'+item.sname+'</option>';
			        });
					obj.append(strBuffer);
					form.render();
				}else{
					layer.msg('数据通信异常~',{icon: 0});
				}
			}
		});
	}
	//'请输入正确数字，且保留两位小数！'
	function isNumberAndFloat1(str) {
		var $ = layui.$, form = layui.form
		if (str.value == '' || str.value == null) {
			return;
		}
		var rgx = /^([-]?)([0-9](\d+)?(\.\d{1,2})?$)|(^\d\.\d{1,2}$)/;

		var boolrgx = rgx.test(str.value);// true
		if (boolrgx) {
			return true;
		} else {
			str.value =0;
			layer.msg('请输入正确数字，且保留两位小数！');
			return false;
		}
	}
	//导出excel
   	function exportList() {
   		layer.msg("暂未上线，敬请期待~",{icon: 1});
		/*var $ = layui.$;
		var params = "?coopCode=";
		params += $('#queryCode').val().trim();
    	params += "&coopName=";
    	params += $('#queryCoopName').val().trim();
    	params += "&addTime=";
    	params += $('#queryAddTime').val().trim();
		params += "&cityName=";
    	params += $('#queryCityName').val().trim();
		params += "&types=";
    	params += $('#queryTypes').val().trim();
		params += "&uptTime=";
    	params += $('#queryUptTime').val().trim();
		params += "&srealName=";
    	params += $('#querySrealName').val().trim();
		window.location.href = "${ctx}/coopinfo/exportCoopInfo"+params;*/
	}
  </script>
</body>
</html>
